﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using JinRi.Services;
using JinRi.Services.Domains;
using JinRiAdmin.WebHost.ViewModels;
using PagedList;

namespace JinRiAdmin.WebHost.Controllers
{
    public class LawController : BaseController
    {
        [HttpGet]
        public ActionResult Banner()
        {
            var item = Service.GetBanner(4);
            if (item == null)
            {
                item = new Banner();
            }

            var model = Mapper.Map<Banner, BannerModel>(item);
            return View(model);
        }


        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Banner(BannerModel model)
        {
            if (ModelState.IsValid)
            {
                Service.SetBanner(4, model.ImageId, model.Introduce);
                return RedirectToAction("Banner");
            }

            ModelState.AddModelError("", "所有字段都要填写。");
            return View(model);
        }
    }
}
